package com.example.partner.adapter.find;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.partner.R;
import com.example.partner.listener.OnImageDeleteListener;

import java.util.List;

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {

    private final List<String> imageList;
    private final Context context;
    public interface OnImageDragListener {
        void onImageDrag(RecyclerView.ViewHolder viewHolder);
    }

    public interface OnImageLongClickListener {
        void onImageLongClick(String imageUrl);
    }

    private OnImageLongClickListener onImageLongClickListener;

    public void setOnImageLongClickListener(OnImageLongClickListener listener) {
        this.onImageLongClickListener = listener;
    }
    public ImageAdapter(Context context, List<String> imageList) {
        this.context = context;
        this.imageList = imageList;
    }


    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, parent, false);

        return new ImageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        String imagePath = imageList.get(position);
        // 在这里加载图片到 ImageView（你可能需要使用图片加载库如 Picasso 或 Glide）
         Glide.with(context).load(imagePath).into(holder.imageView);
// 设置拖拽监听器
// 设置长按监听器
        holder.imageView.setOnLongClickListener(v -> {
            if (onImageLongClickListener != null) {
                onImageLongClickListener.onImageLongClick(imageList.get(position));
                return true;
            }
            return false;
        });
        // 或者直接使用本地路径
//        holder.imageView.setImageURI(Uri.parse(imagePath));
    }

    @Override
    public int getItemCount() {
        return imageList.size();
    }

    public static class ImageViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public ImageViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.image_item);
        }
    }
}
